package com.siki.vo.admin;


import com.siki.pojo.commonEntity.Enterprise;
import com.siki.pojo.commonEntity.GeneralUser;
import com.siki.pojo.commonEntity.SysUser;
import com.siki.pojo.enumeration.common.UserRole;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.Optional;
/**
 * @Author Siki
 * @Date 2020/6/9
 */
@ApiModel("账号详细信息VO")
@Getter
@Setter
@NoArgsConstructor
public class FindEnterpriseVO {
    @ApiModelProperty("id")
    String id;

    @ApiModelProperty("企业名称")
    String realName;

    @ApiModelProperty(value = "企业所在地址")
    private String address;

    @ApiModelProperty(value = "企业邮箱")
    private String email;

    @ApiModelProperty(value = "头像url")
    private String avatarUrl;

    @ApiModelProperty(value = "公司介绍")
    private String introduction;

    public FindEnterpriseVO(SysUser sysUsers){
        Optional.ofNullable(sysUsers).ifPresent(sysUser -> {
            this.id = sysUser.getId();
            this.realName = sysUser.getRealName();
            switch (sysUser.getUserRole()){
                case GENERAL_USER -> {
                    Optional.ofNullable(sysUser.getGeneralUser()).ifPresent(generalUser -> {
                        this.address=generalUser.getAddress();
                        this.email=generalUser.getEmail();
                        this.avatarUrl = generalUser.getAvatarUrl();
                        this.introduction = generalUser.getSelfIntroduction();
                    });
                }
                case BUSINESS_USER -> {
                    Optional.ofNullable(sysUser.getEnterprise()).ifPresent(enterprise -> {
                        this.address=enterprise.getAddress();
                        this.email=enterprise.getEmail();
                        this.avatarUrl = enterprise.getAvatarUrl();
                        this.introduction = enterprise.getIntroduction();
                    });
                }
                case ADMIN_USER -> {}
                default -> throw new RuntimeException("身份信息有误");
            }
        });
    }
}
